<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<LINK href="stylesheet.css" rel="stylesheet" type="text/css">
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>WebBucks Online Coffee Company!</title>
        <style>.error { color: red; } .success { color: green; }</style>
    </head>
    <body>
        <div id="content">
            <div id="loginpane">
                <c:choose>
                    <c:when test="${! empty validUser && validUser == true}">
                        Current User: ${currentUser}
                        <a href="/webbucks-war/IndexServlet?action=logout">Log out</a>
                        <a href="updateCustomer.jsp">Update profile</a>
                    </c:when>
                    <c:otherwise>
                        <a href="login.jsp">Login or register</a>
                    </c:otherwise>
                </c:choose>
                <a href="/webbucks-war/Manager">Manage shop</a>
            </div>
            <a href="/webbucks-war/IndexServlet?action=toIndex">Till startsidan</a>
            <div id="header">
                <h1>WebBucks!</h1>
            </div>
            
            <h2> Products </h2>
            <form name="products" method="POST" action="/webbucks-war/Manager">
                <table>
                    <tr>
                        <th>Delete</th>
                        <th>Name</th>
                        <th>Ingredients</th>                
                        <th>Price</th>
                    </tr>
                    <c:forEach items="${products}" var="product">
                        
                        <tr>
                            <td><input type="checkbox" name="delete_${product.name}" value="${product.name}" />
                            <td>${product.name}</td>
                            <td>
                                Ingredients:{
                                <c:forEach items="${product.ingredients}" var="ingredients">
                                    ${ingredients.name}
                                </c:forEach>
                                }                     
                            </td>
                            <td><input type="text" value="${product.price}" name="price_${product.name}" /></td>
                        </tr>
                    </c:forEach>
                </table>
                
                <input type="submit" value="Change Prices!" />
            </form>
            
            
            
            <h2> Ingredients </h2>
            <form name="ingredients" method="POST" action="/webbucks-war/Manager">
                <table>
                    <tr>
                        <th>Name</th>
                        <th>In Store</th>
                        <th>Number to buy</th>                
                    </tr>
                    <c:forEach items="${supply}" var="ingredients">
                        <tr>
                            <td>${ingredients.name}</td>
                            <td>${ingredients.quantity}</td>
                            <td><input type="text" value="0" name="${ingredients.name}"/></td>
                        </tr>
                    </c:forEach>
                    
                </table>
                
                <input type="submit" value="Buy!" />
            </form>
            
            <br />
            <h2>Add Product!</h2>
            <form name="add_product_form" method="POST" action="/webbucks-war/Manager">
                <p>
                    Product Name: 
                    <input type="text" value="" name="add_product"/>
                </p>
                
                <table>  
                    <tr>
                        <th>Check to add</th>
                        <th>Ingredient name</th>
                    </tr>
                    
                    
                    <c:forEach items="${supply}" var="ingredients">
                        <tr>
                            <td><input type="checkbox" name="add_${ingredients.name}" value="${ingredients.name}" />
                            <td>${ingredients.name}</td>
                        </tr>
                        
                    </c:forEach>
                </table>
                
                <input type="submit" value="Add Product!" />
            </form>
            <form id="logout_form" method="post" action="/webbucks-war/Manager">
                <input type="hidden" name="logout" value="1" />
                <input type="submit" value="Logout!"  />
            </form>
        </div>
    </body>
</html>



